Public Class frmRandom
  Inherits System.Windows.Forms.Form

  ' ====================== Skadniki ====================
  Private MyList As New clsList()

  Private mFileName As String
  Private CurrentRecord As Long
  Private LastRecord As Long

  ' Kod generowany przez Windows Form Designer 

  ' ====================== Waciwoci =================
  Public Property FileName() As String
    Get
      Return mFileName
    End Get

    Set(ByVal NewFileName As String)
      mFileName = NewFileName
    End Set

  End Property

  ' ================= Zdarzenie adowania formularza  ====================

  Private Sub frmRandom_Load(ByVal sender As System.Object, ByVal e As _
                  System.EventArgs) Handles MyBase.Load
    Dim i As Integer

    MyList.FileName = mFileName  ' Kopijemy nazw otwartego pliku do klasy
    LastRecord = MyList.CurrentRecordCount ' Ile jest rekordw?
    CurrentRecord = 1
    If LastRecord > 0 Then         ' Jeli s jakie rekordy...
      FillARecord(1)               ' ...poka pierwszy z nich
    End If
  End Sub

  Private Sub btnAddNew_Click(ByVal sender As System.Object, ByVal e As _
                  System.EventArgs) Handles btnAddNew.Click
    Dim NewRecord As Long
    ClearForm()
    txtFirst.Focus()
  End Sub

  Private Sub ClearForm()   ' Wyczy pola tekstowe
    txtFirst.Text = ""
    txtLast.Text = ""
    txtAddr.Text = ""
    txtCity.Text = ""
    txtState.Text = ""
    txtZip.Text = ""
  End Sub
  Private Sub txtState_Leave(ByVal sender As Object, ByVal e As _
                  System.EventArgs) Handles txtState.Leave
    txtState.Text = UCase(txtState.Text)  ' Zmie stan na due litery 
  End Sub
  Private Sub FillARecord(ByVal rec As Long)
    ' Cel: ta procedura suy do wypeniania pl tekstowych formularza.
    '
    ' Lista argumentw:
    '  rec numer rekordu do odczytania (long integer)
    '
    Dim ErrorFlag As Integer

    ErrorFlag = MyList.ReadRecord(rec) ' Czytamy rekord klasy 
    If ErrorFlag = 0 Then
      Me.Text = "Random Access Files    Record: " & CStr(rec) 
                ' Wstawiamy tytu formularza
      txtFirst.Text = MyList.First
      txtLast.Text = MyList.Last
      txtAddr.Text = MyList.Addr
      txtCity.Text = MyList.City
      txtState.Text = MyList.State
      txtZip.Text = MyList.Zip
    Else
      MessageBox.Show("Read failure")
    End If
  End Sub
